#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@desc: .

@Project ：kuberCloudTest 
@File ：log.py
@Author ：admin
@Date ：2024/3/25 11:17 
"""
import logging
import logging.config
import os
import platform

from kuberCloudTest.exception import KuberCloudException


def getLogger(cls, name='root'):
    def _checkLogDir():
        if str(platform.system()) == 'Windows':
            log_dir = 'C:\\Users\\admin\\kuberCloudTest\\logs'
        else:
            log_dir = '/var/log/kuberCloudTest/'
        if not os.path.exists(log_dir):
            os.makedirs(log_dir)

    def _get_log_ini():
        current_dir = os.path.abspath(os.path.dirname(__file__))

        if str(platform.system()) == 'Windows':
            log_ini = os.path.join(current_dir, 'win_log.ini')
        else:
            log_ini = os.path.join(current_dir, 'linux_log.ini')

        if not os.path.exists(log_ini):
            raise KuberCloudException('internal error', 'log ini is not exists')
        return log_ini

    _checkLogDir()
    log_ini_file = _get_log_ini()
    # log_conf_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'log.ini')
    logging.config.fileConfig(log_ini_file)
    return logging.getLogger(name)


kuberCloudLog = getLogger(__name__)